package com.company.returnsion;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}20:05
 */
public class Queue3 {
    public static int max = 8;
    public static int[] queue = new int[max];

    public static void main(String[] args) {
        Queue3 queue3 = new Queue3();
        queue3.check(0);
    }

    //比较规则
    public boolean judge(int n){
        for (int i = 0; i < n;i++){
            if (queue[i] == queue[n] ||Math.abs(n - i) == Math.abs(queue[n]-queue[i])){
                return false;
            }
        }
        return true;
    }
    //实现方法
    public void check(int n){
        if (n == max){
            print2();
            return;
        }else {//没到最后一行
            //依次放入皇后
            for (int i = 0; i < max;i++){
                queue[n] = i;
                if (judge(n)){
                    check(n+1);
                }
            }
        }
    }

    //输出方法
    public void print2(){
        for (int i = 0; i < queue.length; i++){
            System.out.print(queue[i]+"\t");
        }
        System.out.println();
    }
}
